package com.far.game.xiuzhen.common.conf;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.time.LocalDateTime;

@Slf4j
@Component
public class MyBatisFillHandler implements MetaObjectHandler  {

    @Override
    public void insertFill(MetaObject metaObject) {
        //验证数据是否为null，为NULL就填充
        this.setFieldValByName("createAt", LocalDateTime.now(), metaObject);
        this.setFieldValByName("updateAt", LocalDateTime.now(), metaObject);

    }

    @Override
    public void updateFill(MetaObject metaObject) {
        // 验证字段是否有效 不管是否有值直接填充
        this.setFieldValByName("updateAt", LocalDateTime.now(), metaObject);
       // this.setFieldValByName("updateBy",baseController.getVisitor().getUserName(),metaObject);

    }

    @PostConstruct
    void init(){
        log.info(MyBatisFillHandler.this.getClass().getName());
    }


}
